/*****************************************************************************
* Copyright (c) 2014,H.B.
* All rights reserved.
* 
* FileName : DtvChannel.java
* Description : define DtvChannel
* 
* Version : 0.0.0
* Author : HB   Reviewer : 
* Date : 2014-07-08
* Record : Create
*
* History : 
* (1) Version : 0.0.0
*     Author : HB   Reviewer : 
*     Date : 2014-07-08
*     Record : Create
****************************************************************************/

package hb.dtv;


public class DtvChannel
{
	static public final int SECTION	=	0;
	static public final int PES		=	1;
	static public final int TS		=	2;

	final int mJniPtr;

	DtvChannel(int ptr)
	{
		mJniPtr=ptr;
	}

	public void Release()
	{
		nativeRelease(mJniPtr);
	}

	public void LinkBuffer(DtvBuffer buffer)
	{
		nativeLinkBuffer(mJniPtr,buffer.mJniPtr);
	}

	public void UnlinkBuffer( )
	{
		nativeUnlinkBuffer(mJniPtr);
	}

	public void SetPid(int pid)
	{
		nativeSetPid(mJniPtr,pid);
	}

	public int GetPid( )
	{
		return nativeGetPid(mJniPtr);
	}

	public void Start()
	{
		nativeStart(mJniPtr);
	}
	
	public void Stop()
	{
		nativeStop(mJniPtr);
	}
	
	public int GetHandle()
	{
		return nativeGetHandle(mJniPtr);
	}

	@Override
	public boolean equals(Object o) 
	{
		 if (this == o) return true;
		 if (!(o instanceof DtvChannel)) return false;
		 DtvChannel d=(DtvChannel)o;
		 if(mJniPtr==d.mJniPtr)return true;
		 return nativeGetHandle(mJniPtr)==nativeGetHandle(d.mJniPtr);
	}

	@Override
	protected void finalize() throws Throwable
	{
		nativeDestroy(mJniPtr);
		super.finalize();
	}

	private native static void nativeLinkBuffer(int jniPtr,int buffer);

	private native static void nativeUnlinkBuffer(int jniPtr);
	
	private native static void nativeSetPid(int jniPtr,int pid);
		
	private native static int nativeGetPid(int jniPtr);
		
	private native static void nativeStart(int jniPtr);
		
	private native static void nativeStop(int jniPtr);
		
	private native static int nativeGetHandle(int jniPtr);
	
	private native static void nativeRelease(int jniPtr);
	
	private native static void nativeDestroy(int jniPtr);
}

